import threading

import network
import timer
import handlecommand

network.Init()
oNetWorkManager = network.GetNetWorkManager()

timer.Init()
oTimerManager = timer.GetTimerManager()

handlecommand.Init()
oHandleCommand = handlecommand.CHandleCommand()

class CNetWorkRecvThread(threading.Thread):
    def __init__(self, thread_name):
        super(CNetWorkRecvThread, self).__init__(name=thread_name)

    def run(self):
        print("run network thread")
        oNetWorkManager.StartListen()

class CNetWorkSendThread(threading.Thread):
    def __init__(self, thread_name):
        super(CNetWorkSendThread, self).__init__(name=thread_name)

    def run(self):
        print("run network thread")
        oNetWorkManager.SendLoop()

oNetWorkReceiveThread = CNetWorkRecvThread("newworkrecv")
oNetWorkReceiveThread.start()

oNetWorkSendThread = CNetWorkSendThread("newworksend")
oNetWorkSendThread.start()

while True:
    lstPackage = oNetWorkManager.PopAllPackage()
    oHandleCommand.OnHandle(lstPackage)
    oTimerManager.OnLoop()